package app.beit.finportal.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import app.beit.finportal.entity.Documents;

public class DocumentsDao extends BaseDao<Documents> {

	@SuppressWarnings("unchecked")
	public List<Documents> getAllBackdoor() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final List<Documents> results = session.createQuery("from Documents").list();
		session.close();
		return results;
	}
	
	@SuppressWarnings("unchecked")
	public List<Documents> getAll() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final List<Documents> results = session.createQuery("from Documents where status='1' order by updated_date desc").list();
		session.close();
		return results;
	}
	
	@SuppressWarnings("unchecked")
	public List<Documents> getAllLastedDate() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query query = session.createQuery("from Documents where status='1' order by updated_date desc");
		query.setFirstResult(0);
		query.setMaxResults(8);
		final List<Documents> results = query.list();
		session.close();
		return results;
	}
	
	@SuppressWarnings("unchecked")
	public List<Documents> getAllLastestDate() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query q = session.createQuery("from Documents where status='1' order by updated_date desc");
		q.setFirstResult(0);
		q.setMaxResults(8);
		final List<Documents> results = q.list();
		
		session.close();
		return results;
	}
	
}
